feature: support for all databases supported by laravel to the functionality for sorting alphanumeric values #149
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found after some analysis that the syntax being used to sort alphanumeric values
field+0
is not compatible with all databases supported by Laravel. I also discovered that some logs were being dropped into the database, as illustrated below.Output Logs on MySQL Server
So I did some research and came up with some possible syntaxes for such sorting. But each database used its own syntax to perform the task, because of this difference in syntax I implemented a function called
getSortSqlByDriver
where with it we can successfully perform an alphanumeric sort. All we need to do is to inform some parameters when we call the function:Some auxiliary methods have also been developed, for example:
Each query was tested against its respective database, and all returned the same database records. Below we can see the returned records already sorted alphanumerically.
Query Results
After implementation, the tests were run and all passed successfully.
Tests Results
Larastan and PHP CS Fixer Results
EXTRA
In order to minimize the inconvenience that may be caused by installing and configuring databases, and to avoid diverging scenarios, I am also proposing to add a
docker-compose
file to the project repository, so that we can easily orchestrate Docker containers, for all currently supported database versions.I increased the number of the database ports by
1
so that I could avoid any kind of conflict due to local versions running on the default ports. Thus, we have the following connection ports for the database containers :I suggest that the test environments be set to the given ports, thus maintaining a standard and avoiding conflicts with local versions of the databases.
References